package com.zone.gateway.core.bind;

import com.zone.gateway.core.session.GatewaySession;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.Map;

/**
 * @author: zongzi
 * @description: 泛化调用代理增强类，委托”MappedProxy“执行引擎最终执行rpc泛化调用
 * @date: 2025/4/17
 */
public class MappedProxy implements MethodInterceptor {

    private final String uri;
    private final GatewaySession gatewaySession;

    public MappedProxy(String uri, GatewaySession gatewaySession) {
        this.uri = uri;
        this.gatewaySession = gatewaySession;
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        MappedMethod mappedMethod = new MappedMethod(uri, gatewaySession);
        // 取第一个参数
        return mappedMethod.execute(method, (Map<String, Object>) objects[0]);
    }
}
